n = int(input())
s = []
for _ in range(n):
    k,l,r = map(int, input().split())
    s.append([k,l,r])

def transform(x,k):

    a=[0,1,2,3,4,5,6,7,8,9,'A','B','C','D','E','F']
    b=[]
    while True:
        s = x//k
        y = x%k
        b = b+[y]
        if s == 0:
            break
        n=s
    b.reverse()
    for i in b:
        print(a[i],end='')
transform(16,2)